<%@page import="pojo.Account"%>
<%@page import="pojo.Category"%>
<%@page import="pojo.Manufacturer"%>
<%@page import="pojo.Product"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>

<h2>Danh Sách Sản Phẩm</h2> 
<div class="warning_box">
    Cảnh Báo.
</div>
<div class="valid_box">
    Xác Nhận.
</div>
<div class="error_box">
    Lỗi.
</div> 
<table id="rounded-corner" summary="Danh Sách Sản Phẩm">
    <thead>
        <tr>
            <th width="34" class="rounded-company"></th>
            <th width="47" class="rounded">STT</th>
            <th width="284" class="rounded">Tên</th>
            <th width="111" class="rounded">Loại sản phầm</th>
            <th width="76" class="rounded">Đơn giá</th>
            <th width="109" class="rounded">Hãng sản xuất</th>
            <th width="76" class="rounded">Ngày thêm</th>
            <th width="68" class="rounded-q4">Thao tác</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <td colspan="7" class="rounded-foot-left"><em>Danh sách sản phẩm hiện hành của Baby Fashion Shop.</em></td>
            <td width="15" class="rounded-foot-right">&nbsp;</td>
        </tr>
    </tfoot>
    <tbody> 
        <c:choose>
            <c:when test="${MESSAGE != 'PAGE_NOT_FOUND' && MESSAGE != 'PAGE_EMPTY'}">
                <c:forEach items = "${ITEM_LIST}" var = "p" varStatus="status">
                    <tr>
                        <td><input type="checkbox" name="" /></td>
                        <td>${(CURRENT_PAGE - 1) * ITEM_PER_PAGE + status.count}</td>
                        <td>${p.getName()}</td>
                        <td>${CATEGORY_DAO.getCategory(p.getCategory().getId()).getName()}</td>
                        <td>${p.getUnitPrice()}</td>
                        <td>${MANUFACTURER_DAO.getManufacturer(p.getManufacturer().getId()).getName()}</td>
                        <td><fmt:formatDate pattern="dd-MM-yyyy" value="${p.getDate()}" /></td>
                        <td>

                            <a href="/quanly.htm?view=quanlysanpham&act=edit&id=${p.getId()}"><img src="Style/Admin/images/user_edit.png" alt="" title="" border="0" /></a>
                            &nbsp;&nbsp;&nbsp;
                            <a href="/quanly.htm?view=quanlysanpham&act=delete&id=${p.getId()}" class="ask"><img src="Style/Admin/images/trash.png" alt="" title="" border="0" /></a>
                        </td>
                    </tr>
                </c:forEach>  
            </c:when>
            <c:when test="${MESSAGE == 'PAGE_EMPTY'}">
            <td colspan="7" class="rounded-foot-left">Không có sản phẩm nào trong mục này</td>
            <td width="15" class="rounded-foot-right">&nbsp;</td>
        </c:when>                
        <c:when test="${MESSAGE == 'PAGE_NOT_FOUND'}">
            <td colspan="7" class="rounded-foot-left">Trang này không tồn tại</td>
            <td width="15" class="rounded-foot-right">&nbsp;</td>
        </c:when>
    </c:choose>
</tbody>
</table>
<!--
<div class="pagination">
    <span class="disabled"><< prev</span>
    <span class="current">1</span>
    <a href="">2</a>
    <a href="">3</a>
    <a href="">4</a>
    <a href="">5</a>
    ...
    <a href="">10</a>
    <a href="">11</a>
    <a href="">12</a>
    ...
    <a href="">100</a>
    <a href="">101</a>
    <a href="">next >></a>
</div>
-->
<div class = "pagination">   
    <c:choose>
        <c:when test="${MESSAGE != 'PAGE_NOT_FOUND' && MESSAGE != 'PAGE_EMPTY'}">
            <c:choose>
                <c:when test="${CURRENT_PAGE != 1}">   
                    <a href="/quanly.htm?view=quanlysanpham&act=view&page=${CURRENT_PAGE - 1}&item=${ITEM_PER_PAGE}"><< prev</a>                        
                </c:when>
                <c:otherwise>            
                    <span class="disabled"><< prev</span> 
                </c:otherwise>
            </c:choose> 
            <c:choose>
                <c:when test="${TOTAL_PAGE > 20}">    

                    <c:forEach var="page" begin="1" end="2" step="1" >
                        <c:choose>
                            <c:when test="${page == CURRENT_PAGE}">
                                <span class="current">${CURRENT_PAGE}</span>
                            </c:when>
                            <c:otherwise> 
                                <a href="/quanly.htm?view=quanlysanpham&act=view&page=${page}&item=${ITEM_PER_PAGE}">${page}</a>  
                            </c:otherwise>
                        </c:choose>
                    </c:forEach>              
                    <c:if test="${CURRENT_PAGE > 5}">
                        ......
                    </c:if>
                    <c:forEach var="page" begin="3" end="${TOTAL_PAGE - 2}" step="1" >
                        <c:choose>
                            <c:when test="${page == CURRENT_PAGE}">
                                <span class="current">${CURRENT_PAGE}</span>
                            </c:when>
                            <c:when test="${(page - CURRENT_PAGE) < 3 && (page - CURRENT_PAGE) > 0|| (CURRENT_PAGE - page) < 3 && (CURRENT_PAGE - page) > 0}">
                                <a href="/quanly.htm?view=quanlysanpham&act=view&page=${page}&item=${ITEM_PER_PAGE}">${page}</a>   
                            </c:when>
                            <c:otherwise> 
                            </c:otherwise>
                        </c:choose>
                    </c:forEach>              
                    <c:if test="${CURRENT_PAGE < TOTAL_PAGE - 4}">
                        ......
                    </c:if>
                    <c:forEach var="page" begin="${TOTAL_PAGE - 1}" end="${TOTAL_PAGE}" step="1" >
                        <c:choose>
                            <c:when test="${page == CURRENT_PAGE}">
                                <span class="current">${CURRENT_PAGE}</span>
                            </c:when>
                            <c:otherwise> 
                                <a href="/quanly.htm?view=quanlysanpham&act=view&page=${page}&item=${ITEM_PER_PAGE}">${page}</a>   
                            </c:otherwise>
                        </c:choose>
                    </c:forEach>                        
                </c:when>
                <c:otherwise>           
                    <c:forEach var="page" begin="1" end="${TOTAL_PAGE}" step="1" >
                        <c:choose>
                            <c:when test="${page == CURRENT_PAGE}">
                                <span class="current">${CURRENT_PAGE}</span>
                            </c:when>
                            <c:otherwise>
                                <a href="/quanly.htm?view=quanlysanpham&act=view&page=${page}&item=${ITEM_PER_PAGE}">${page}</a>                                    
                            </c:otherwise>
                        </c:choose>
                    </c:forEach>  
                </c:otherwise>
            </c:choose> 
            <c:choose>
                <c:when test="${CURRENT_PAGE != TOTAL_PAGE}">   
                    <a href="/quanly.htm?view=quanlysanpham&act=view&page=${CURRENT_PAGE + 1}&item=${ITEM_PER_PAGE}">next >></a>                        
                </c:when>
                <c:otherwise>            
                    <span class="disabled">next >></span> 
                </c:otherwise>
            </c:choose> 
        </c:when>
        <c:when test="${MESSAGE == 'PAGE_EMPTY'}">
            <span class="disabled"><< prev</span>
            <span class="current">1</span>
            <span class="disabled">next >></span>>
        </c:when>                
        <c:when test="${MESSAGE == 'PAGE_NOT_FOUND'}">
            <a href="/quanly.htm?view=quanlysanpham&act=view&page=1&item=${ITEM_PER_PAGE}">Không tồn tại trang này, nhấn vào đây để quay trở lại</a>
        </c:when>
    </c:choose>
</div>
<a href="#" class="bt_green"><span class="bt_green_lft"></span><strong>Add new item</strong><span class="bt_green_r"></span></a>
<a href="#" class="bt_blue"><span class="bt_blue_lft"></span><strong>View all items from category</strong><span class="bt_blue_r"></span></a>
<a href="#" class="bt_red"><span class="bt_red_lft"></span><strong>Delete items</strong><span class="bt_red_r"></span></a> 
<script type="text/javascript" src="Script/jquery-1.8.2.js"></script>
<script type="text/javascript">
    $(document).ready(function(){ 
        $(".warning_box").hide();
        $('.valid_box').hide();
        $('.error_box').hide();
        var a = "${MESSAGE}";
        if(a == "PAGE_NOT_FOUND")
        {
            $('.error_box').html("Không tìm thấy trang này.");
            $(".error_box").show("slow");
        }   
        if(a == "PAGE_EMPTY")
        {
            $('.warning_box').html("Không có sản phẩm nào trong dữ liệu.");
            $(".warning_box").show("slow");
        }           
        if(a == "PRODUCT_DELETE_SUCCESS")
        {
            $('.valid_box').html("Đã xóa thành công sản phẩm.");
            $(".valid_box").show("slow");
        } 
        if(a == "PRODUCT_NOT_EXIST")
        {
            $('.error_box').html("Không tìm thấy sản phẩm cần xóa.");
            $(".error_box").show("slow");
        } 
        if(a == "PRODUCT_DELETED")
        {
            $('.warning_box').html("Sản phẩm cần xóa đã bị xóa.");
            $(".warning_box").show("slow");
        }   
    })	
</script>